package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.ui.contract.LoginContract
import com.baizan.daka.mvp.model.UserModel
import com.baizan.daka.mvp.model.bean.LoginInfoBean
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.util.Md5

class LoginPresenter(val mView: LoginContract.View) : BasePresenter(),
    LoginContract.Presenter {


    private val userModel: UserModel by lazy {
        UserModel()
    }


    override fun login(account: String, password: String) {
        mView.showLoadingDialog()
        userModel.login(account, Md5.getPasswordMd5(password))//+"baiwandianzanmima"
            .subscribe(object : CommonSubscriber<LoginInfoBean>(compositeDisposable) {

                override fun onCallNext(t: LoginInfoBean?) {
                    mView.loginSuccess(t!!,account)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }


}

